package com.yyq.gxdc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyq.gxdc.entity.Cart;
import com.yyq.gxdc.mapper.CartMapper;
import com.yyq.gxdc.service.ICartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements ICartService {
    @Resource
    private CartMapper cartMapper;

    @Override
    public PageInfo<Cart> findPage(Cart conditioin, int pageNum, int pageSize) {
        return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> {
            cartMapper.find(conditioin);
        });
    }
    @Override
    public int add(Cart cart) {
        return cartMapper.insert(cart);
    }
    @Override
    public Cart findById(Integer id) {
        return cartMapper.findById(id);
    }

    @Override
    public Cart getDetailByRid(Integer rid){
        Cart cart = cartMapper.findById(rid);

        return cart;
    }

    @Override
    public int update(Cart cart) {
        return cartMapper.updateById(cart);
    }
    @Override
    public int delete(Integer id) {
        return cartMapper.deleteById(id);
    }


    @Override
    public void updateCart(Cart cart){
        cartMapper.updateById(cart);
    }

    @Override
    public Cart findByUidAndDishId(Integer uid,Integer dishId){
        Cart byUidAndDishId = cartMapper.findByUidAndDishId(uid, dishId);
        return byUidAndDishId;
    }

    @Override
    public void deleteByUidAndDishId(Integer uid,Integer dishId){
        Cart byUidAndDishId = cartMapper.findByUidAndDishId(uid, dishId);
        cartMapper.deleteById(byUidAndDishId.getId());
    }

    @Override
    public IPage<Cart> getAllCart(Page<Cart> page, Cart conditioin){
        return cartMapper.getAllCart(page,conditioin);
    };
}

